package org.kfive.nova.Servlet;

import javax.servlet.AsyncContext;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * Created by admin on 2017-04-30.
 */
public class AsyncRequestProcessor implements Runnable {
    private AsyncContext asyncContext;
    private int secs;

    public AsyncRequestProcessor(AsyncContext asyncContext,int secs){
        this.asyncContext = asyncContext;
        this.secs = secs;
    }
    @Override
    public void run() {
        System.out.print("async thread start to run");
        System.out.println("Async Supported? "
                + asyncContext.getRequest().isAsyncSupported());
        try {
            Thread.sleep(60000);
            PrintWriter out = this.asyncContext.getResponse().getWriter();
            out.write("Processing done for " + secs + " milliseconds!!");
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }

        asyncContext.complete();
    }
}
